package xiancherng;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class jiekio {
    private  String name;
    private String wx;
    //创建一个Lock对象
    private Lock cl =new ReentrantLock();

    public String getWx() {
        return wx;
    }

    public void setWx(String wx) {
        this.wx = wx;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    private double money;

    public jiekio() {
    }

    public jiekio(String name, double money,String wx) {
        this.wx=wx;
        this.name = name;
        this.money = money;
    }

    public void Drawmany(double m) {
        String name=Go12.currentThread().getName();
        try {
            cl.lock();//加锁
            if (money>=m) {
                System.out.println(name+"剩余的钱"+m);
                money-=m;
                System.out.println(name+"剩余的钱"+money);

            }else {
                System.out.println(name+"取完");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            cl.unlock();//解锁
        }
    }
}
